package com.group.his.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.group.his.entity.Department;
import com.group.his.entity.Register;
import com.group.his.entity.User;
import com.group.his.service.BRegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 */
@RestController
public class BRegisterController {
    @Autowired
    BRegisterService bRegisterService;
    @RequestMapping("GetCostServlet")
    public Object getRegistCostById(int id) {
        return bRegisterService.getRegistCostById(id);
    }
    @RequestMapping("GetPatientServlet")
    public Object getPatientByIdNum(String idNum) {
       return bRegisterService.getPatientByIdNum(idNum);
    }
    @RequestMapping("GetDepartmentServlet")
    public List<Department> getAllDepartment() {
       return bRegisterService.getAllDepartment();
    }
    @RequestMapping("GetDoctorServlet")
    public List<User> getDoctorByDepidLevelid(int depid, int levelId){
      return bRegisterService.getDoctorByDepidLevelid(depid,levelId);
    }
    @PostMapping("RegistServlet")
    public Object regist(String idnumber,String realName,String gender,String age,String ageType,String homeAddress,String birthDate,String noon,String deptID,String registLeID,
                         String userID,String isBook) {
        QueryWrapper<Register> queryWrapper=new QueryWrapper();
        queryWrapper.orderByDesc(Register.CASENUMBER);
        Register register=new Register();
        register.setIDnumber(idnumber);
        register.setRealName(realName);
        register.setAgeType(ageType);
        register.setAge(Integer.parseInt(age));
        register.setHomeAddress(homeAddress);
        register.setBirthDate(birthDate);
        register.setNoon(noon);
      register.setDeptID(Integer.parseInt(deptID));
      register.setRegistLeID(Integer.parseInt(registLeID));
      register.setUserID(Integer.parseInt(userID));
      register.setIsBook(isBook);
      register.setGender(Integer.parseInt(gender));
      register.setCaseNumber(bRegisterService.list(queryWrapper).get(0).getCaseNumber()+1);
     int res=Integer.parseInt( String.valueOf(bRegisterService.regist(register)));
     if(res>0){
         return "添加成功";
     }
     return "添加失败";
    }
}

